package sort;

import java.util.Arrays;

public class SelectSort implements MySort {
    public static void main(String[] args) {
        int a[] = {1,78,35,29,156,88,66};
        //int a[] = {1,2,3,4,5,6,7};
        selectSort(a);
        System.out.println(Arrays.toString(a));
    }

    private static void selectSort(int[] a) {
        int length = a.length;
        int min = 0;
        int temp;
        for (int i=0;i<length-1;i++){
            min=i;
            for (int j=i+1;j<length;j++){
                if(a[j]<a[min]){
                    min=j;
                }
            }

            if(min!=i){
                temp = a[min];
                a[min] = a[i];
                a[i] = temp;
            }
        }
    }

    @Override
    public void sort(int[] a) {
        int length = a.length;
        int min = 0;
        int temp;
        for (int i=0;i<length-1;i++){
            min=i;
            for (int j=i+1;j<length;j++){
                if(a[j]<a[min]){
                    min=j;
                }
            }

            if(min!=i){
                temp = a[min];
                a[min] = a[i];
                a[i] = temp;
            }
        }
    }
}
